package com.lhhu.demo.controller;

import com.lhhu.demo.bean.BookMessage;
import com.lhhu.demo.config.LogAnnotation;
import com.lhhu.demo.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/3/6 11:28
 * @Version 1.0
 */
@RestController
public class BooksController {
    @Autowired
    private BooksService booksService;

    @RequestMapping("/index")
    public String index(){
        return "index";
    }

    @GetMapping("/getAllBookMessage")
    public List<BookMessage> getAllBookMessage(){
        return booksService.getAllBookMessage();
    }

    @LogAnnotation(module = "图书管理模块",action = "新增图书")
    @PostMapping("/addOneBookMessage")
    public int addOneBookMessage(String codes,String bookName,String bookSynopsis,double bookOprice,double bookPprice,int bookCounts,String bookUrl,String bookISBN,String bookCategoryId,String bookTag){
        BookMessage bookMessage = new BookMessage();
        bookMessage.setBookName(bookName);
        bookMessage.setBookSynopsis(bookSynopsis);
        bookMessage.setBookOprice(bookOprice);
        bookMessage.setBookPprice(bookPprice);
        bookMessage.setBookCounts(bookCounts);
        bookMessage.setBookUrl(bookUrl);
        bookMessage.setBookISBN(bookISBN);
        bookMessage.setBookCategoryId(bookCategoryId);
        bookMessage.setBookTag(bookTag);
        return booksService.addOneBookMessage(codes,bookMessage);
    }

    @LogAnnotation(module = "图书管理模块",action = "删除图书")
    @DeleteMapping("/deleteOneBookMessage")
    public int deleteOneBookMessage(String codes,String bookId){
        return booksService.deleteOneBookMessage(codes,bookId);
    }

    @LogAnnotation(module = "图书管理模块",action = "更新图书信息")
    @PutMapping("/updateOneBookMessage")
    public int updateOneBookMessage(String codes,String bookId,String bookName,String bookSynopsis,double bookOprice,double bookPprice,int bookCounts,String bookUrl,String bookISBN,String bookCategoryId,String bookTag){
        BookMessage bookMessage = new BookMessage();
        bookMessage.setBookId(bookId);
        bookMessage.setBookName(bookName);
        bookMessage.setBookSynopsis(bookSynopsis);
        bookMessage.setBookOprice(bookOprice);
        bookMessage.setBookPprice(bookPprice);
        bookMessage.setBookCounts(bookCounts);
        bookMessage.setBookUrl(bookUrl);
        bookMessage.setBookISBN(bookISBN);
        bookMessage.setBookCategoryId(bookCategoryId);
        bookMessage.setBookTag(bookTag);
        return booksService.updateOneBookMessage(codes,bookMessage);
    }

    @GetMapping("/getOneBookMessageById")
    public List<BookMessage> getOneBookMessageById(String bookId){
        return booksService.getOneBookMessageById(bookId);
    }

    @GetMapping("/getAllBookMessageByISBN")
    public List<BookMessage> getAllBookMessageByISBN(String bookISBN){
        return booksService.getAllBookMessageByISBN(bookISBN);
    }

    @GetMapping("/getAllBookMessageByName")
    public List<BookMessage> getAllBookMessageByName(String bookName){
        return booksService.getAllBookMessageByName(bookName);
    }

    @GetMapping("/getAllBookMessageByCategoryId")
    public List<BookMessage> getAllBookMessageByCategoryId(String bookCategoryId){
        return booksService.getAllBookMessageByCategoryId(bookCategoryId);
    }

    @GetMapping("/getAllBookMessageByCategory")
    public List<BookMessage> getAllBookMessageByCategory(String bookCategory){
        return booksService.getAllBookMessageByCategory(bookCategory);
    }

    @GetMapping("/getAllBookMessageByTag")
    public List<BookMessage> getAllBookMessageByTag(String bookTag){
        return booksService.getAllBookMessageByTag(bookTag);
    }
}
